package com.system.depart.controller;

import com.system.depart.bean.Depart;
import com.system.depart.service.DepartService;
import com.system.depart.vo.DepartItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: DepartController
 * @description: TODO 类描述
 * @author: Li Chuanwei
 * @date: 2023/10/31 20:46
 * @Company: Copyright [日期] by [作者或个人]
 **/

@RestController
@RequestMapping("/depart")
public class DepartController {
    @Autowired
    private DepartService departService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Depart depart){
        return departService.saveDepart(depart);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return departService.removeDepartById(id);
    }

    @PutMapping("/upd")
    public boolean updateHandle(@RequestBody Depart depart){
        return departService.modifyDepart(depart);
    }

    @GetMapping("/get/{id}")
    public Depart getHandle(@PathVariable("id") int id){
        return departService.getDepartById(id);
    }

    @GetMapping("/get/list")
    public List<Depart> listHandle(){
        return departService.listAllDeparts();
    }

    @GetMapping("/getAllParent/list")
    public List<Depart> listParentHandle(){
        return departService.listAllParentDeparts();
    }

    @GetMapping("/getChild/{id}")
    public List<Depart> listChildHandle(@PathVariable("id") int id){
        return departService.listChildDeparts(id);
    }

    @GetMapping("/getDepartName/{id}")
    public String getDepartName(@PathVariable("id") int id){
        return departService.getDepartName(id);
    }

    @GetMapping("/get/departItemVOlist")
    public List<DepartItemVO> getDepartItemVOList(){
        return departService.getDepartItemVO();
    }

    @GetMapping("/getAllChild/list")
    public List<Depart> listAllChildHandle(){
        return departService.listAllChildDeparts(0);}

}
